<?php

namespace Cyfy\Modules\Objects;

/**
 * Class for creating light-box like overlay
 */
class Overlay extends GeneralObject
{
    /**
     * Title
     * @var string
     */
    private $title = '';
     
    /**
     * Alternative link
     * @var string
     */
    private $link = '#';
    
    /**
     * Creates a new overlay
     */
    function __construct($name = '')
    {
        $this -> name = $name;
    }
    
    function setTitle($title, $link = '#')
    {
        $this -> title = $title;
        $this -> link = $link;
    }
    
    function setData($data)
    {
        $this -> data = $data;        
    }
    
    function show()
    {
        // data
        \Cyfy\Template :: addFooter("<div id=\"{$this->name}Overlay\" style=\"display:none;\"></div><div id=\"{$this->name}OverlayInner\" class=\"overlay-inner\" style=\"display:none;\">{$this->data}</div>");
        
        // ADD JS
        \Cyfy\Cyfy ::  javaScript(\Cyfy\Cyfy ::  getSourcePath("Cyfy/Modules/Objects/overlay.js"), "file");
        // css
        \Cyfy\Cyfy ::  css(\Cyfy\Cyfy ::  getSourcePath("Cyfy/Modules/Objects/overlay.css"));
        
        
        // link
        $link = "<a href=\"{$this->link}\" onclick=\"Overlay.show('{$this -> name}'); return false;\" class=\"overlay-link\">" . $this->title . "</a>";
        return $link;
    }


}